﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using CostaRicaPureTravel.UserControls;
using CostaRicaPureTravel.Controller;
using CostaRicaPureTravelUtils.EmailConfiguration;
using System.Xml;
using System.Data;
using System.IO;
using System.Net;
using WorldDomination.Net;
using CostaRicaPureTravelUtils.log;
using CostaRicaPureTravelUtils.location;


namespace CostaRicaPureTravel
{
    public partial class Shop : System.Web.UI.Page
    {
        private EmailController controller;
        private String COUNTRY_NAME = "Costa Rica";
        protected void Page_Init(object sender, EventArgs e)
        {
            controller = new EmailController(this.Context);
            AjaxPopUp.EventDelegate = btnOkEvent;
            String countryName = RemoteClientLocation.getClientLocation(Request.UserHostAddress);
        /*    if (String.IsNullOrEmpty(countryName) || !countryName.Equals(COUNTRY_NAME)) {
                LitNotAvai.Visible = true;               
                formTable.Visible = false;
                formContact.Visible = false;
                Literal2.Visible = false;
            }*/
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            
            
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                if (Page.IsValid)
                {
                    String name = String.Format("{0} {1}", txtFirstName.Text, txtLastName.Text);
                    String body = EmailContent.getEmailTemplate(EmailContent.EmailType.SHOP, name, txtPhone.Text,  txtMessage.Text, SelectedValues.Value);
                    controller.Send(txtEmailAddress.Text, name, EmailContent.SHOP_PRODUCTS, body, true);

                    if (checkSendMeCopy.Checked)
                            controller.Send(txtEmailAddress.Text, txtFirstName.Text, "", txtMessage.Text, false);
                }
                else
                {
                    return;
                }
            }
            catch (Exception)
            {
                AjaxPopUp.MessageType = AjaxBasedPopUpControl.PopupMessageType.Error;
                AjaxPopUp.Message = "CONTACT_GENERAL_ERROR";
            }
            AjaxPopUp.ShowPopupMessage();
        }

        protected void btnOkEvent(object sende, EventArgs e)
        {
            Response.Redirect(ResolveUrl("Shop.aspx"));
        }
    }
}